/*-------------------------------------------------------
\u52a0\u8f7d\u6587\u4ef6\u57fa\u7840\u65b9\u6cd5\uff0c\u65b9\u4fbf\u5916\u7f51\u8c03\u7528\u4f7f\u7528
mericmo
*--------------------------------------------------------*/
if(typeof(BaseManager) == 'undefined'){
	BaseManager = function(){};
}
BaseManager.globe = {
	initiallize:false
};
BaseManager.init = function(opt){
	//全局扩展
	BaseManager.win();
	//基类扩展
	BaseManager.base();
	//实例化基类
	BaseManager.instant();
	//工具类扩展
	BaseManager.extTools();
	
};
//工具类扩展
BaseManager.extTools=function(){
	//扩展Dom操作类
	//扩展cookie操作类
	$extend(window,{'$cookie':BaseManager.cookie()});
	//扩展url操作类
	$extend(window,{'$url':BaseManager.url()});
	//扩展hashMap //初步认为可以用json代理
	//扩展Json
	$extend(window,{'$json':BaseManager.json()});
	//事件扩展
};
//全局扩展
BaseManager.win =function(){
	//dom \u9009\u62e9\u5668
	var $id = function(element){
		if(arguments.length == 0){
			return document;
		}
		if(arguments.length == 1){
			if(typeof(element) == 'string'){
				element = element.replace(/^#/, '');
				return document.getElementById(element);
			}
			return element;
		}
		for(var i = 0, elements = [], length = arguments.length; i < length; i++){
			elements.push($id(arguments[i]));
		}
		return elements;
	};
	//\u5bf9\u8c61\u7ee7\u627f
	var $extend = function(option, opt) {
		if(typeof(opt) != 'object' || !opt){
			return option;
		}
		for(var property in opt){
			option[property] = opt[property];
		}
		return option;
	};
	//\u57fa\u7840\u547d\u540d\u7a7a\u95f4\u751f\u6210\u5668
	var $namespace = function(){
		var arg = arguments;
		if(arg.length == 1){
			if(!arg[0]){
				return;
			}
			arg = arg[0].split(',');
		}
		var _this = this;
	    for(var i = 0; i < arg.length; i++){
	    	if(!arg[i]){
	    		continue;
	    	}
	        var _temp = arg[i].split('.');
			var obj = _this;
	        for(var j = 0; j < _temp.length; j++){
	        	var argus = "\\s";
			var temp = new RegExp("(^"+argus+"*)|("+argus+"*$)","g");
			_temp[j] = _temp[j].replace(temp, '');

	            obj[_temp[j]] = obj[_temp[j]] || {};
	            obj = obj[_temp[j]];
	        }
	    }
	};

	var $typeof = function(obj){
		if(obj == undefined){
			return 'undefined';
		}
		//if (obj.$family) return (obj.$family.name == 'number' && !isFinite(obj)) ? false : obj.$family.name;
		if(obj.nodeName){
			switch(obj.nodeType){
				case 1: return 'element';
				case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
			}
		}else if(typeof(obj.length) == 'number'){
			if(obj.callee){
				return 'arguments';
			}else if(obj.item){
				return 'collection';
			}
		}
		return typeof(obj);
		};	
	
	var $loadCss = function(path,callback){
		if(!path){return false;}
		var l;
		if(!window["_loadCss"] || window["_loadCss"].indexOf(path)<0){
				l = document.createElement('link');
				l.setAttribute('type', 'text/css');
				l.setAttribute('rel', 'stylesheet');
				l.setAttribute('href', path);
				l.setAttribute("id","loadCss"+Math.random());
				document.getElementsByTagName("head")[0].appendChild(l);
				window["_loadCss"]?(window["_loadCss"]+="|"+path):(window["_loadCss"]="|"+path);
		}
		l&&(typeof callback=="function")&&(l.onload=callback);
		return true;
	};
	
	var $loadUrl = function(o){
		 o.element = o.element || 'script';//url:"",element:"img/script"
		var el = document.createElement(o.element);
		el.charset = o.charset || 'utf-8';
		if(o.noCallback==true){
			el.setAttribute("noCallback","true");
		}
		el.onload = el.onreadystatechange = function() {
			if(/loaded|complete/i.test(this.readyState) || navigator.userAgent.toLowerCase().indexOf("msie") == -1) {
				clear();
			}
		};
		el.onerror = function(){
			clear();
		};
		el.src = o.url;

		document.getElementsByTagName('head')[0].appendChild(el);
		
		function clear(){
			if(!el){return ;}
			el.onload = el.onreadystatechange = el.onerror = null;
			el.parentNode&&(el.parentNode.removeChild(el));
			el = null;
		}
	};
	//loadScript start
	var $loadScript = function(obj){
		//创建一个script并加载script
		//原始参数：id:'放置script的id',  url:'载入的地址',obj:'其他配置';
		//定义全局计数器
		if(!$loadScript.counter) {
			$loadScript.counter = 1;
		}
		var isObj = typeof (obj) == "object", url = isObj ? obj.url : arguments[0], id = isObj ? obj.id : arguments[1], obj = isObj ? obj : arguments[2], //参数处理
		_head = document.head || document.getElementsByTagName("head")[0] || document.documentElement, //
		_script = document.createElement("script"), D = new Date(), _time = D.getTime(), //script标签的属性id的时间戳
		_isCleared = false, _timer = null, //定时器对象
		o = obj || {}, //扩展参数对象
		data = o.data || '', //可选，get数据  支持对象{p1:1,p2:2}和字符串p1=1&p2=2
		charset = o.charset || "gb2312", //可选，编码方式
		timeout = o.timeout, //可选，超时时间，单位：毫秒
		reportRetCodeName = o.reportRetCodeName,
		//可选，异步接口返回数据的错误码字段名称，无默认值。
		reportSuccessCode = typeof (o.reportSuccessCode) == "undefined" ? 200 : o.reportSuccessCode,
		//可选，接口返回成功的状态码，默认为200，指cgi成功返回。设置了reportRetCodeName时，reportSuccessCode将无效。
		reportErrorCode = typeof (o.reportErrorCode) == "undefined" ? 500 : o.reportErrorCode,
		//可选，接口返回错误的状态码，默认为500，泛指cgi不可用。
		reportTimeoutCode = typeof (o.reportTimeoutCode) == "undefined" ? 600 : o.reportTimeoutCode,
		//可选，接口超时的状态码，默认为600，指cgi超时。
		onload = o.onload, //可选，加载完成
		onsucc = o.onsucc,
		callbackName = o.callbackName || '', //可选，回调函数名称
		callback = o.callback, //可选，回调函数体
		errorback = o.errorback, //可选，错误回调函数体，参数为错误码。
		_jsonpLoadState = 'uninitialized';
		/**清除处理函数
		 *  @errCode: reportSuccessCode, reportErrorCode,  reportTimeoutCode
		 */
		var complete = function(errCode) {
			//防止重复执行的问题
			if(!_script || _isCleared) {
				return;
			}
			_isCleared = true;

			//清除定时器
			if(_timer) {
				clearTimeout(_timer);
				_timer = null;
			}

			//防止IE内存泄漏
			_script.onload = _script.onreadystatechange = _script.onerror = null;

			//清除script元素
			if(_head && _script.parentNode) {
				_head.removeChild(_script);
			}
			_script = null;

			//清除全局临时回调函数
			if(callbackName) {
				if(callbackName.indexOf('.') == -1) {
					window[callbackName] = null;
					try {
						delete window[callbackName];
					}
					catch (e) {
					}
				}
				else {
					var arrJ = callbackName.split("."), p = {};
					for(var j = 0, jLen = arrJ.length; j < jLen; j++) {
						var n = arrJ[j];
						if(j == 0) {
							p = window[n];
						}
						else {
							if(j == jLen - 1) {
								try {
									delete p[n];
								}
								catch (e) {
								}
							}
							else {
								p = p[n];
							}
						}
					}
				}
			}

			//CGI返回数据错误或超时时执行
			if(_jsonpLoadState != "loaded" && typeof errorback == "function") {
				errorback(errCode);
			}
		};
		var jsontostr = function(d) {
			var a = [];
			for(var k in d) {
				a.push(k + '=' + d[k]);
			}
			return a.join('&');
		};

		if(data) {
			url += (url.indexOf("?") != -1 ? "&" : "?") + ( typeof data == 'string' ? data : jsontostr(data));
		}
		
		//创建一个临时全局函数，执行回调函数
		if(callbackName && typeof callback == "function") {
			var oldName = callbackName;
			if(callbackName.indexOf('.') == -1) {
				callbackName = window[callbackName] ? callbackName + $loadScript.counter++ : callbackName;
				window[callbackName] = function(jsonData) {
					_jsonpLoadState = 'loaded';
					if(isAutoReport && reportRetCodeName) {
						reportSuccessCode = jsonData[reportRetCodeName];
					}
					//原生的回调函数,改为此方式保证非单一参数回调的正确执行
					callback.apply(null, arguments);
					onsucc&& (onsucc());
				};
			}
			else {
				var arrJ = callbackName.split("."), p = {}, arrF = [];
				for(var j = 0, jLen = arrJ.length; j < jLen; j++) {
					var n = arrJ[j];
					if(j == 0) {
						p = window[n];
					}
					else {
						if(j == jLen - 1) {
							p[n] ? ( n = n + $loadScript.counter++) : '';
							p[n] = function(jsonData) {
								_jsonpLoadState = 'loaded';
								if(isAutoReport && reportRetCodeName) {
									reportSuccessCode = jsonData[reportRetCodeName];
								}
								//原生的回调函数,改为此方式保证非单一参数回调的正确执行
								callback.apply(null, arguments);
								onsucc&& (onsucc());
							};
						}
						else {
							p = p[n];
						}
					}
					arrF.push(n);
				}
				callbackName = arrF.join('.');
			}
			url = url.replace('=' + oldName, '=' + callbackName);
		}


		_jsonpLoadState = 'loading';
		id = id ? (id + _time) : _time;
		_script.charset = charset;
		_script.id = id;

		//加载jsonp数据成功
		_script.onload = _script.onreadystatechange = function() {
			var uA = navigator.userAgent.toLowerCase();
			//非ie与ie判断
			if(!(!(uA.indexOf("opera") != -1) && uA.indexOf("msie") != -1) || /loaded|complete/i.test(this.readyState)) {
				if( typeof onload == "function") {
					onload();
				}
				//loaded
				complete(_jsonpLoadState == "loaded" ? reportSuccessCode : reportErrorCode);
			}
		};
		//加载jsonp数据错误，支持safari,chrome,firefox,ie9
		_script.onerror = function() {
			//cgi error
			complete(reportErrorCode);
		};
		//设置超时
		if(timeout) {
			_timer = setTimeout(function() {
				complete(reportTimeoutCode);
			}, parseInt(timeout, 10));
		}
		setTimeout(function() {
			//在IE下执行此语句时，则会发出请求；其他浏览器则需要插入dom后才会发出请求。
			_script.src = url;
			try{   //加了个try catch, 在IE6，IE7下，上面执行_script.src后，_script会为null，然后insertBefore就报错了，虽然也不会弹窗，但为了避免对自测试的干扰，这里加入了try catch，排除这个错误。
				_head.insertBefore(_script, _head.lastChild);
			}catch(e){}
		}, 0);
	};
	var TT = {
		//'Class' : Class,
		'$id' : $id,
		'$extend' : $extend,
		'$namespace' : $namespace,
		'$loadCss' : $loadCss,
		'$loadUrl' : $loadUrl,
		'$loadScript' : $loadScript
	};
	
	//\u8fd9\u4e9b\u65b9\u6cd5\u6bd4\u8f83\u57fa\u7840\uff0c\u63d0\u5347\u5230window\u4e0b
	$extend(window, TT);
};

//基类扩展
BaseManager.base =function(){
	//类扩展
	var Class = {
		create : function(options){
			options = options || {};
			var option = {
				'name' : '',
				'legacy' : null,
				'protect' : false,
				'initialize' : function(){},
				'implement' : null,
				'afterImplement' : function(){}
			};
			option = $extend(option, options);

			var _class = option.legacy || function(arg){};
			
			if(!_class.prototype){
				_class.prototype = {};
			}

			_class.create = function(){
				var obj = new _class(arguments);
				
				var initialize = option.initialize;
				if(arguments.length == 1 && typeof(arguments[0]) == 'object' && arguments[0]){
					var temp = arguments[0];
					initialize = temp.initialize ? temp.initialize : option.initialize;
				}

				initialize.apply(obj, arguments);
				return obj;
			};
			
			var add = function(obj, name, method, force){
				if (!option.protect || force || !obj.prototype[name]){
					obj.prototype[name] = method;
				}				
				option.afterImplement.call(obj, name, method);
				return obj;
			};
			_class.implement = function(a1, a2, a3){
				if(typeof(a1) == 'string'){
					return add(this, a1, a2, a3);
				}
				//toString
				if((a1.toString + '[native code]').indexOf() < 0){
					add(this, 'toString', a1.toString, a3);
				}

				for(var p in a1){
					add(this, p, a1[p], a2);
				}
				return this;
			};
			_class.alias = function(a1, a2, a3){
				if(typeof(a1) == 'string'){
					var pa1 = this.prototype[a1];
					if(pa1){
						return add(this, a2, pa1, a3);
					}
				}
				for(var a in a1){
					this.alias(a, a1[a], a2);
				}
				return this;
			};

			_class.constructor = Class;
			_class.prototype.constructor = _class;
			
			var globalFun = {
				init : function(){},
				toString : function(){},
				clone : function(){}
			};
		
			_class.implement(globalFun);
			
			if(option.implement){
				_class.implement(option.implement);
			}
			return _class;
		}
	};
	$extend(window, {'Class':Class});
};
//实例化基类
BaseManager.instant = function(){
	var natives = {'Array': Array, 'Date': Date, 'Function': Function, 'Number': Number, 'RegExp': RegExp, 'String': String, 'Math': Math};
	for(var n in natives){
		Class.create({name : n, legacy : natives[n], protect : true});
	}
	//String
	(function(String){
		String.implement({
			
			trim : function(){
				var argus = arguments[0] || "\\s";
				var temp = new RegExp("(^"+argus+"*)|("+argus+"*$)","g");
				return this.replace(temp, '');
			},
			
			ltrim : function(){
				var argus  = arguments[0] || "\\s";
				var temp = new RegExp("(^"+argus+"*)","g");
				return this.replace(temp, '');
			},

			rtrim : function(){
				var argus  = arguments[0] || "\\s";
				var temp = new RegExp("("+argus+"*$)","g");
				return this.replace(temp, '');
			},
			replaceAll : function(str1, str2){
				var temp = this.split(str1 + '').join(str2 + '');
				return temp;
			},
			//把中文按2个字符处理，返回字符串长度
			cLen : function(){
				return this.replace(/[\u00FF-\uFFFF]/g,"  ").length;
			},
			//把中文按2个字符处理，返回字符串从startid到endid的内容
			cSubString : function(start,end){
				var returnStr = '';
				var currentNum = 0;  //当前处理到的字符在字符串中的位置
				if(!end){
					end = this.replace(/[\u00FF-\uFFFF]/g,"  ").length;
				}
				for(var i = 0;i < this.length; i++){
					if(start <= currentNum && currentNum < end){
						returnStr += this.charAt(i);
					};
					currentNum += (this.charCodeAt(i) <= 128 ? 1 : 2);
				};
				return returnStr;
			},
			
			cLeft : function(num1){
				return this.cSubString(0, num1);
			},
			//按照指定字节长度截取字符串，超出部分用…（或者其他字符）代替
			showLeft : function(len){
				var endString  = arguments[1] || "\u2026"; //…
				var returnString = this.cLeft(parseInt(len));
				if(returnString.cLen() < this.cLen()){
					returnString += endString;
				}
				return returnString;
			},

			//把字符串进行HTML编码
			encodeHTML : function(){
				var tempvar = this.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll("'","&apos;").replaceAll("\"","&quot;");
				return tempvar;
			},
			unencodeHTML : function(){
				var tempvar = this.replaceAll("&quot;","\"").replaceAll("&apos;","'").replaceAll("&gt;",">").replaceAll("&lt;","<").replaceAll("&amp;","&");
				return tempvar;
			},
			//文本的标准格式化
			formatText : function(){
				var outputStr = this;
				if(!outputStr){
					return '';
				}
				outputStr = outputStr.replace(/ |\u3000/ig,""); // 
				outputStr = outputStr.replace(/\r\n/ig,"\n");
				outputStr = outputStr.replace(/\n\n/ig,"\n");
				outputStr = outputStr.replace(/\n\n/ig,"\n");
				outputStr = outputStr.replace(/\n\n/ig,"\n");
				outputStr = outputStr.replace(/\n\n/ig,"\n");
				outputStr = outputStr.replace(/\n/ig,"\n\n\u3000\u3000"); //　　
				outputStr = outputStr.replace("\n\n","");
				return outputStr;
			}
		
		});
	})(String);
	
	//Number
	(function(Number){
		Number.implement({
			randomInt:function(){
				var arg = arguments;
				if(arg.length == 0){
					throw new Error('Number.randomInt param wrong;');
					return 0;
				}
				if(arg.length == 1){
					return Math.floor(Math.random() * arg[0]);
				}
				if(arg.length == 2){
					var min = arg[0];
					var max = arg[1];
					return Math.floor(Math.random() * (max - min + 1) + min);
				}
				throw new Error('Number.randomInt param wrong;');
				return 0;
			},
			toFixed:function(len, isTruncate){
				isTruncate = isTruncate ? true : false;
				var tempStr = this.toString();

				{//检查len
					if(typeof(len) != 'number' || isNaN(len) || len*1 < 0){
						return tempStr;
					}
					len = parseInt(len, 10);
					if(len > 30){
						//对不起，您的数字精度超过了限度，最长的保留小数位数为30位。
						alert("\u5bf9\u4e0d\u8d77\uff0c\u60a8\u7684\u6570\u5b57\u7cbe\u5ea6\u8d85\u8fc7\u4e86\u9650\u5ea6\uff0c\u6700\u957f\u7684\u4fdd\u7559\u5c0f\u6570\u4f4d\u6570\u4e3a30\u4f4d\u3002");
						len = 30;
					}
				}
				
				var start_ = tempStr.indexOf('.');
				if(start_ < 0){//为整数
					return tempStr;
				}

				{//用字符串来处理该方法
					var zh = "", x = "", z = 0;
					var start_ = tempStr.indexOf(".");
					if(start_ < 0){
						//例如：314;
						zh = tempStr;
						x = "";
						z = len;
					}else{
						//例如：314.00;
						zh = tempStr.substring(0, start_);
						if(!zh){
							//例如：.00;
							zh = "0";
						}
						
						var temp_ = tempStr.substr(start_ + 1);
						if(temp_){
							//例如：314.005;
							if(temp_.length <= len){
								//例如：314.005; len=5;
								x = temp_;
								z = len - temp_.length;
							}else{
								//例如：314.005; len=2;
								if(len == 0){
									x = "";
								}else{
									x = temp_.substr(0, len);
									if(!isTruncate){
										var _b = temp_.substr(len, 1);
										if(_b*1 >= 5){
											//如果后一位大于5则进一,进一是最后一个位置进一，记得。
											var arrNum = [];
											for(var i = 0; i < len; i++){
												arrNum.push(x.charAt(i));
											}
											var _m = 0;
											for(var j = len-1; j >= 0; j--){
												arrNum[j]++;
												if(arrNum[j] <= 9){
													break;
												}
												arrNum[j] = 0;
												if(j == 0){
													_m = 1;
												}
											}
											zh = zh*1 + _m;
											x = arrNum.join('');
										}
									}
								}
								z = 0;
							}
						}else{
							//例如：314.;
							x = "";
							z = len;
						}
					}
					
					if(z > 0){
						for(var i = 0; i < z; i++){
							x += "0";
						}
					}
					if(x){
						return (zh + "." + x);
					}
					return zh;			
				}
			}//toFixed done
		});
	})(Number);
	
	//Math
	(function(Math){
		Math.add = function(num1, num2){
			var str1 = num1.toString(), str2 = num2.toString();
			var m1 = 0, m2 = 0;
			try{
				if(str1.split('.').length == 2){
					m1 = str1.split('.')[1].length;
				}
			}catch(e){}
		
			try{
				if(str2.split('.').length == 2){
					m2 = str2.split('.')[1].length;
				}
			}catch(e){}
			
			var m = Math.pow(10, Math.max(m1, m2));
			return (Math.mul(num1, m) + Math.mul(num2, m)) / m;
		};
		
		Math.sub = function(num1, num2){
			return Math.add(num1, -num2);
		};
		
		Math.mul = function(num1, num2){
			var str1 = num1.toString(), str2 = num2.toString();
			var m = 0;
			try{
				if(str1.split('.').length == 2){
					m += str1.split('.')[1].length;
				}
			}catch(e){}
			
			try{
				if(str2.split('.').length == 2){
					m += str2.split('.')[1].length;
				}
			} catch(e){}
			return Number(str1.replace('.','')) * Number(str2.replace('.','')) / Math.pow(10, m);
		};
		
		Math.div = function(num1, num2){
			var str1 = num1.toString(), str2 = num2.toString();
			var m1 = 0, m2 = 0;
			try{
				if(str1.split('.').length == 2){
					m1 = str1.split('.')[1].length;
				}
			}catch(e){}
		
			try{
				if(str2.split('.').length == 2){
					m2 = str2.split('.')[1].length;
				}
			}catch(e){}
			
			var m = Math.pow(10, Math.max(m1, m2));
			num1 = Math.mul(num1, m);
			num2 = Math.mul(num2, m);
			return (num1 / num2);
		};
	})(Math);
	
	//Array
	(function(Array){
		Array.implement({
			
		});
		
		//数组Array的扩展
		Array.prototype.contains = function(obj){
			for(var i = 0; i < this.length; i++){
				if(this[i] === obj){
					return true;
				}
			}
			return false;
		};
		//得到一个数组不重复的元素集合
		Array.prototype.uniquelize = function(){
			var ra = [];
			for(var i = 0; i < this.length; i++){
				if(!ra.contains(this[i])){
					ra.push(this[i]);
				}
			}
			return ra;
		};
		Array.prototype.indexOf = function(o){
			var arr = this;
			for(var i = 0; i < arr.length; i++){
				if(arr[i] === o){
					return i;
				}
			}
			return -1;
		};
		//数组删除等于one的元素
		Array.prototype.remove = function(one){
			var ra = [];
			for(var i = 0; i < this.length; i++){
				if(this[i] === one){
					continue;
				}
				ra.push(this[i]);
			}
			return ra;
		};
		Array.prototype.defaultSort = function(){
			this.sort(function(a, b){
				return a.localeCompare(b);
			});
			return this;
		};
		
		//求两个数组的交集
		Array.intersect = function(a, b){
			a = a.uniquelize();
			var newArr = [];
			for(var i = 0; i < a.length; i++){
				var o = a[i];
				if(b.contains(o)){
					newArr.push(o);
				}
			}
			return newArr;
		};
		//求两个数组的差集
		Array.minus = function(a, b){
			a = a.uniquelize();
			b = b.uniquelize();
			var _minArr = [];
			if(a.length == 0){
				return b;
			}
			if(b.length == 0){
				return a;
			}
			for(var i = 0; i < a.length; i++){
				if(!b.contains(a[i])){
					_minArr.push(a[i]);
				}
			}
			for(var i = 0; i < b.length; i++){
				if(!a.contains(b[i])){
					_minArr.push(b[i]);
				}
			}
			return _minArr.uniquelize();
		};
		//求两个数组的并集
		Array.union = function(a, b){
			return a.concat(b).uniquelize();
		};
		//求两个集合的补集
		Array.complement = function(a, b){
			return Array.minus(Array.union(a, b),Array.intersect(a, b));
		};
	})(Array);
	
	//Date
	(function(Date){
		//格式化日期格式。比如：new Date().format('yyyy-mm-dd');
		Date.prototype.format = function(formatStr){
			if(typeof(formatStr) != 'string'){
				formatStr = 'yyyy-MM-dd hh:mm:ss';
			}
			var str = formatStr; 
			str=str.replace(/yyyy|YYYY/,this.getFullYear()); 
			str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():"0" + (this.getYear() % 100)); 
			str=str.replace(/MM/,this.getMonth()>8?(this.getMonth()+1).toString():"0" + (this.getMonth()+1));
			str=str.replace(/M/g,this.getMonth()+1); 
			str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():"0" + this.getDate()); 
			str=str.replace(/d|D/g,this.getDate());
			str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():"0" + this.getHours()); 
			str=str.replace(/h|H/g,this.getHours()); 
			str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():"0" + this.getMinutes()); 
			str=str.replace(/m/g,this.getMinutes()); 
			str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():"0" + this.getSeconds()); 
			str=str.replace(/s|S/g,this.getSeconds());
			return str; 
		};
		//日期比较
		Date.prototype.compare = function(objDate) { 
			if(typeof(objDate)!="object" && objDate.constructor != Date){
				return -2; 
			}
			var d = this.getTime() - objDate.getTime();
			if(d > 0){
				return 1;
			}else{
				if(d == 0){
					return 0;
				}else {
					return -1;
				}
			}
		};
		//针对不同的时间单位做加运算(如果传负数则为减运算)，得到日期年月日等加数字后的日期
		Date.prototype.dateAdd = function(number, interval) {
			var date = this;
			if(typeof(number) == 'undefined' || isNaN(number)){
				number = 1;
			}
			if(typeof(interval) != 'string'){
				interval = 'd';
			}
			switch(interval){
				case "y" : {date.setFullYear(date.getFullYear()+number); break;}
				case "q" : {date.setMonth(date.getMonth()+number*3); break;}
				case "m" : {date.setMonth(date.getMonth()+number); break;} 
				case "w" : {date.setDate(date.getDate()+number*7); break;}
				case "d" : {date.setDate(date.getDate()+number); break;}
				case "h" : {date.setHours(date.getHours()+number); break;}
				case "M" : {date.setMinutes(date.getMinutes()+number); break;}
				case "s" : {date.setSeconds(date.getSeconds()+number); break;}
				default : {date.setDate(date.getDate()+number); break;}
			}
			return date;
		};
		//判断闰年
		Date.prototype.isLeapYear = function(){
			return (0 == this.getYear() % 4 && ((this.getYear() % 100 != 0)||(this.getYear() % 400 == 0)));
		};


		//根据时间格式字符串得到时间对象
		//年:yyyy|YYYY|yy|YY
		//月:MM|M
		//日:dd|DD|d|D
		//时:hh|HH|h|H
		//分:mm|m
		//秒:ss|SS|s|S
		Date.parse = function(dateStr, formatStr) {
			if(dateStr instanceof Date){
				return dateStr;
			}
			if(typeof(formatStr) != 'string'){
				formatStr = 'yyyy-MM-dd hh:mm:ss';
			}
			
			var dateObjStr = {
				yearStr		: '',
				monthStr	: '',
				dateStr		: '',
				hourStr		: '00',
				minuteStr	: '00',
				secondStr	: '00'
			};
			
			{//寻找年日时秒的数字
				var reg = /(y{2,4})|(d{1,2})|(h{1,2})|(s{1,2})/ig;
				var all_ = formatStr.match(reg);
				for(var i = 0; i < all_.length; i++){
					all_[i] = all_[i].toLowerCase();
					var str_ = dateStr.substr(formatStr.indexOf(all_[i]), all_[i].length);
					if(str_ && !isNaN(str_) && str_*1 == parseInt(str_*1, 10)){
						if(/y+/.test(all_[i])){//表示是年
							dateObjStr.yearStr = str_;
						}
						if(/d+/.test(all_[i])){//表示是日
							dateObjStr.dateStr = str_;
						}
						if(/h+/.test(all_[i])){//表示是时
							dateObjStr.hourStr = str_;
						}
						if(/s+/.test(all_[i])){//表示是秒
							dateObjStr.secondStr = str_;
						}
					}
				}
			}
			
			{//寻找月分的数字
				var reg = /M{1,2}/g;
				var all_ = formatStr.match(reg);
				if(all_ && all_.length == 1){
					var str_ = dateStr.substr(formatStr.indexOf(all_[0]), all_[0].length);
					if(str_ && !isNaN(str_) && str_*1 == parseInt(str_*1, 10)){
						dateObjStr.monthStr = str_;
					}
				}
				
				reg = /m{1,2}/g;
				all_ = formatStr.match(reg);
				if(all_ && all_.length == 1){
					var str_ = dateStr.substr(formatStr.indexOf(all_[0]), all_[0].length);
					if(str_ && !isNaN(str_) && str_*1 == parseInt(str_*1, 10)){
						dateObjStr.minuteStr = str_;
					}
				}
			}
			
			{//将格式标准化
				var date_ = new Date();
				if(!dateObjStr.dateStr){
					dateObjStr.dateStr = String(date_.getDate());
				}
				if(!dateObjStr.monthStr){
					dateObjStr.monthStr = String(date_.getMonth()+1);
				}
				if(!dateObjStr.yearStr){
					dateObjStr.yearStr = String(date_.getFullYear());
				}
				var _dateStr = dateObjStr.yearStr +'-'+ dateObjStr.monthStr +'-'+ dateObjStr.dateStr +' '+ dateObjStr.hourStr +':'+ dateObjStr.minuteStr +':'+ dateObjStr.secondStr;
			}
			return new Date(dateObjStr.yearStr*1, (dateObjStr.monthStr*1-1), dateObjStr.dateStr*1, dateObjStr.hourStr*1, dateObjStr.minuteStr*1, dateObjStr.secondStr*1);
		};
	})(Date);
	
	//Function
	(function(Function){
		Function.implement({
			runEach:function(t){
				var A = this;
				var B = Array.prototype.slice.call(arguments,1);
				var f = function(){
					A.apply(null,B);
				}; 
				return setInterval(f, t);
			},
			runAfter:function(t){
				var A = this;
				var B = Array.prototype.slice.call(arguments,1);
				var f = function(){
					A.apply(null, B);
				};
				return setTimeout(f,t);
			}
		});
	})(Function);
};
//扩展url操作类
BaseManager.url =function(){
	$url={
		getNoCacheFromUrl : function(url, ts){
			url = url || ((typeof(window) != 'undefined' && window && window.location && window.location.href)?window.location.href:'') || '';
			ts = ts || '_';
			var tsStr = ts + "=" + randomInt(10000);
			if(url.indexOf("?") > 0){
				var _value = this.getQuery(ts, url);
				if(_value){
					url = url.replace(new RegExp(ts+'=([^&]*)', 'gi'), tsStr);//表示如果存在该变量则替换
				 }else{
					url += "&" + tsStr;
				 }
			 }else{
			  url += "?" + tsStr;
			 }
			 return url;
		},
		getQuery : function(name,url){
			var u  = url || window.location.href;
			var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			var r = u.substr(u.indexOf("\?")+1).match(reg);
			if (r!=null) {
				return decodeURIComponent(r[2]);
			 } 
			 return "";
		}
	};
	return $url;
};
//扩展cookie类
BaseManager.cookie = function(){
	$cookie = {
		getCookie : function (name) {
			//读取COOKIE
			var reg = new RegExp("(^| )" + name + "(?:=([^;]*))?(;|$)"), val = document.cookie.match(reg);
			return val ? (val[2] ? unescape(val[2]) : "") : null;
		},
		setCookie : function(name, value, expires, path, domain, secure) {
			//写入COOKIES
			var exp = new Date(), expires = arguments[2] || null, path = arguments[3] || "/", domain = arguments[4] || null, secure = arguments[5] || false;
			expires ? exp.setMinutes(exp.getMinutes() + parseInt(expires)) : "";
			document.cookie = name + '=' + escape(value) + ( expires ? ';expires=' + exp.toGMTString() : '') + ( path ? ';path=' + path : '') + ( domain ? ';domain=' + domain : '') + ( secure ? ';secure' : '');
			return document.cookie;
		},
		delCookie : function(name, path, domain, secure) {
			//删除cookie
			var value = this.getCookie(name);
			if(value != null) {
				var exp = new Date();
				exp.setMinutes(exp.getMinutes() - 1000);
				path = path || "/";
				document.cookie = name + '=;expires=' + exp.toGMTString() + ( path ? ';path=' + path : '') + ( domain ? ';domain=' + domain : '') + ( secure ? ';secure' : '');
			}
		}
	};
	return $cookie;
};

//扩展json类
BaseManager.json = function(){
	$json = {
		 clone : function(o){
            if(typeof(o) != 'object'){
                return o;
            }
            if(o == null){
                return null;
            }
            var n = (o.constructor == Array) ? [] : {};
            for(var i in o){
                n[i] = JsonObject.clone(o[i]);
            }
            return n;
        },
		each : function(jsonObj, callBackFun){
            if(typeof(jsonObj) != 'object' || typeof(callBackFun) != 'function'){
                return;
            }
            if(jsonObj instanceof Array){//数组
                for(var i = 0; i < jsonObj.length; i++){
                    if(callBackFun(i, jsonObj[i])){
                        return;
                    }
                }
            }else{
                for(var i in jsonObj){//对象
                    if(callBackFun(i, jsonObj[i])){
                        return;
                    }
                }
            }
        }
	};
};

//闭包自检
(function(){
BaseManager.init();
})();